/**
 *  环保智库服务-统计-环保智库分类统计
 *  Created by dinghh on 2018/7/13.
 */
'use strict';
angular.module("MetronicApp").directive('divideBar', function () {
    return {
        scope: {
            id: "@",
            data: "="
        },
        restrict: 'EA',
        template: '<div style="width: 1200px;height: 300px;margin: 30px auto"></div>',
        replace: true,
        link: function ($scope, element, attrs, controller) {
            function getOption(data) {
                var option = {
                    title:{                       //标题
                        text:'环保智库分类统计',
                        left:'50%',
                        top:'5%',
                        textAlign:'center',
                        textStyle:{//标题内容的样式
                            fontSize:16,//主题文字字体大小，默认为18px
                            color: '#4169E1'
                        }
                    },
                    legend:{
                        data:['总数据量'],
                        left:'center',
                        bottom:'1%'
                    },
                    color: ['#40E0D0'],
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '15%',
                        containLabel: true
                    },
                    xAxis : [
                        {
                            type : 'category',
                            data : ['产业政策库', '民生经济库', '能源信息库库', '技术创新库', '模型算法库', '解决方案库', '标准体系库']
                        }
                    ],
                    yAxis : [
                        {
                            min:0,
                            max:1200,
                            type : 'value'
                        }
                    ],
                    series : [
                        {
                            name:'总数据量',
                            type:'bar',
                            barWidth: '70%',
                            data:[500, 1050, 1050, 790, 610, 590, 1100],
                            itemStyle:{
                                normal:{
                                    barBorderRadius:5
                                }
                            }
                        }
                    ]
                };
                return option;
            }
            var myChart = echarts.init(document.getElementById($scope.id), 'macarons');
            myChart.setOption(getOption());

            $scope.$watch('data', function (newVal, oldVal) {
                myChart.setOption(getOption(newVal));
            });
        }
    };
});
